package com.leetcode.array_matrix;

/**
 * @author Dennis Li
 * @date 2020/7/29 20:27
 */
public class ConstructArray_667 {

    public int[] constructArray(int n, int k) {
        int[] nums = new int[n];
        int i = 1, j = k + 1;
        int index = 0;
        // 添加交替数组
        while (i <= j) {
            nums[index++] = i;
            if((k & 1) == 0 && i == j) break;
            nums[index++] = j--;
            i++;
        }
        i = k + 2;
        while (i <= n) {
            nums[index++] = i++;
        }
        return nums;
    }

}
